package org.geekbang.projects.rest.core;

import javax.ws.rs.core.Response;

/**
* 默认状态类型  
* @author : KangNing Hu
*/
public class DefaultStatusType implements Response.StatusType {


	/**
	 * 网络状态码
	 */
	private int code;

	/**
	 * 状态提示语
	 */
	private String phrase;

	/**
	 * 状态族
	 */
	private Response.Status.Family family;

	public DefaultStatusType(int code){
		this.code = code;
		init();
	}

	/**
	 * 初始化
	 */
	private void init() {
		if (code < 200){
			this.phrase = "代表请求已被接受，需要继续处理";
		}else if (code < 300){
			this.phrase = "请求已成功被服务器接收、理解、并接受";
		}else if (code < 400){
			this.phrase = "客户端采取进一步的操作才能完成请求";
		}else if (code < 500){
			this.phrase = "请求错误";
		}else {
			this.phrase = "服务器在处理请求的过程中有错误或者异常";
		}
		this.family = Response.Status.Family.familyOf(this.code);
	}


	@Override
	public int getStatusCode() {
		return this.code;
	}

	@Override
	public Response.Status.Family getFamily() {
		return this.family;
	}

	@Override
	public String getReasonPhrase() {
		return this.phrase;
	}
}
